/**
 * Created by Administrator on 2016/9/19.
 */

//轮播图实现


        $(".lbt-item>a:not(:first)").hide();
        var index1 = 0;

        //右按钮
        $(".back").click(function () {
            $(".lbt-item>a").eq(index1).hide();
            index1++;

            if (index1 > 4) {
                index1 = 0;
            }
            $(".lbt-item>a").eq(index1).fadeIn(400);
            $(".controlUl>li").removeClass("active");
            $(".controlUl>li").eq(index1).addClass("active");
        })

        //左按钮
        $(".goahead").click(function () {
            $(".lbt-item>a").eq(index1).hide();
            index1--;

            if (index1 < 0) {
                index1 = 4;
            }
            $(".lbt-item>a").eq(index1).fadeIn(400);
            $(".controlUl>li").removeClass("active");
            $(".controlUl>li").eq(index1).addClass("active");
        });

        //下面的小控制按钮
        $(".controlUl>li").click(function () {
            $(".lbt-item>a").hide();
            $(".lbt-item>a").eq($(this).index()).fadeIn(400);
            $(".controlUl>li").removeClass("active");
            $(".controlUl>li").eq($(this).index()).addClass("active")

        });

        //自动播放
        // var timer;
        var player1 = function () {
            timer1 = setInterval(function () {
                $(".back").trigger("click");
            }, 5000);
        }


        $(".lbt-top").on({
            mouseover: function () {
                $(".lbt-control").next().stop().fadeIn(600);
                $(".lbt-control").next().next().stop().fadeIn(600);
                 clearInterval(timer1);
            },
            mouseout: function () {
                $(".lbt-control").next().stop().fadeOut(600);
                $(".lbt-control").next().next().stop().fadeOut(600);
                player1();
            }
        });
        player1();






//   六十秒闪购





    var e = new Date("2018/10/1");
    var count = 0;
    var timer = setInterval(function(){
        count++;
        var s = new Date();
        var html1=getDiff1(s,e);
        $("#time1").html(html1);
        return count;
    },1000);
    if(count>60){
        clearInterval(timer)
    }





function getDiff1(start,end){
    var time1 = start.getTime();
    var time2 = end.getTime();

    var diff = time2-time1;

    var s = parseInt(diff/1000);
    var ls = s%60;
    var m = parseInt(s/60);
    var lm = m%60;
    var h = parseInt(m/60);
    var lh = h%24;
    var d = parseInt(h/24);
    var str = ls + "秒";
    var fenge=str.replace("-","")
    return fenge;

}
//    请求所有图片
        $.get("../json/fastshop.json", function (data) {

            for(var j = 0;j<data.length;j++){
                var html = "";
               // console.log(data[j].ul)
                $.each(data[j].ul,function(i,o){

                    html += "<li>"
                        + "<a href=\"#\">"
                            + "<img src=\"" + o.img + "\">"
                            + "<p class=\"desc\">"
                            + " <span class='bao'>" + o.desc + "</span>"
                            + " " + o.intro + " "
                            + "</p>"
                            + " <p class=\"newPrice\">" + o.newPrice + "</p>"
                            + " <p class=\"oldPrice\">" + o.oldPrice + "</p>"
                            + " <p class=\"qiang\">" + o.qiang + "</p>"
                            + " <p class=\"changeBg\"></p>"
                        + " </a>"
                        + " </li>";
                })
                $(".fastItem-container>ul").eq(j).html(html);
            }

            $(".fastItem ul li").hover(function(){
                var $a = $(this).children().children();

                $a.last().stop().animate({
                    height:122,
                },600);

                $a.eq(1).children().css("background","#fff");
                // $a.eq(1).children().css("color","#fff");
                $(this .bao).css("color","#ff666b");
                $a.eq(2).css("color","yellow");
                $a.eq(3).css("color","#fff");
                $a.eq(4).css({
                    color:"#ff666b",
                    background:"#fff"
                });

            },function(){
                var $a = $(this).children().children();
                $a.last().stop().animate({
                    height:0,
                },600)
                $a.eq(1).children().css("background","#fff");
                // $a.eq(1).children().css("color","#fff");
                $(this .bao).css("color","#ff666b");
                $a.eq(2).css("color","#ff666b");
                $a.eq(3).css("color","#9e9e9e");
                $a.eq(4).css({
                    color:"#fff",
                    background:"#ff666b"
                });
            });



        });



        //给右侧按钮添加点击事件
        var index2 = 0;
        $(".next").click(function(){
            var len = $(".fastItem-container>ul").length;
            index2++;
            //console.log(index)
            if(index2 > len-1){
                index2 = 0;
                $(".fastItem-container").css("left",0);
            }
            $(".fastItem-container").stop().animate({
                left:-1180*index2
            },400);
            $(".fastControl>span").removeClass("active");
            $(".fastControl>span").eq(index2).addClass("active");
        });


//给右侧按钮添加点击事件
        $(".prve").click(function(){
            var len = $(".fastItem-container>ul").length;
            index2--;
            //console.log(inde2x)
            if(index2 <0){
                index2 = len-1;
                $(".fastItem-container").css("left",-1180*len-1);
            }
            $(".fastItem-container").stop().animate({
                left:-1180*index2
            },400);
            $(".fastControl>span").removeClass("active");
            $(".fastControl>span").eq(index2).addClass("active");
        });


//    自动播放
//         var player2 = function(){
//             timer2 = setInterval(function(){
//                 $(".next").trigger("click")
//             },60000)
//         }
//         player2();


        setInterval(function(){
           //console.log($("#time1").children())
           // console.log($(".t1Img").offset().top);

        },1000);



//热门活动
//if($(this).offset().top<$(window).height + $(window).scrollTop)
var flag1 = true;
$(window).scroll(function(){
    $("#hotActive").each(function(i,o){
        if($(window).height() + $(window).scrollTop() > $(o).offset().top
            && $(window).scrollTop() < $(o).height() + $(o).offset().top&&flag1){
            flag1 = false;
            $.get("../json/hotActive.json",function(data){

                // console.log(data);
                var html = "";
                $.each(data,function(i,o){

                    html += "<li>"
                        +"<a href=\"#\">"
                        +"<img src=\""+o.imgSrc+"\"/>"
                        +"</a>"
                        +"<p class=\"countTime\">"
                        +"<span class=\"iconfont\">&#xe63f;</span>"
                        +"剩余天数："
                        +"<span class=\"count\"></span>"
                        +"</p>"
                        +"</li>";
                    $("#hotActive>ul").html(html);

                });
                // console.log($("#hotActive>ul>li>#count").length)
                var e = new Date("2016/10/1");
                setInterval(function(){
                    // console.log(i);
                    var s = new Date();
                    var html1=getDiff(s,e);
                    // console.log($("#count"))

                    $(".count").html(html1);
                },1000);

            });
        }
    });
});




function getDiff(start,end){
    var time1 = start.getTime();
    var time2 = end.getTime();

    var diff = time2-time1;

    var s = parseInt(diff/1000);
    var ls = s%60;
    var m = parseInt(s/60);
    var lm = m%60;
    var h = parseInt(m/60);
    var lh = h%24;
    var d = parseInt(h/24);
    var str = d + "天" + lh + "时" + lm + "分" + ls + "秒";
    var fenge=str.replace("-","")
    return fenge;

}


// 人气爆棚
var flag2 = true;
$(window).scroll(function(){
    $("#manLike").each(function(i,o){
        if($(window).height() + $(window).scrollTop() > $(o).offset().top
            && $(window).scrollTop() < $(o).height() + $(o).offset().top&&flag2){
            flag2 = false;
            $.get("../json/manLike.json",function(data){
                // console.log(data)
                var html0 = "";
                $.each(data,function(i,o){
                    html0 += "<li>"
                        +"<a  href=\"#\">"
                        +"<span class=\"img\">"
                        +"<img src=\""+o.imgSrc+"\"/>"
                        +"</span>"
                        +" <p class=\"intro\">"+o.intro+"</p>"
                        +"</a>"
                        +" <p class=\"price\">"
                        +"<span class=\"newPrice\">"+o.newPrice+"</span>"
                        +"<span class=\"oldPrice\">"+o.oldPrice+"</span>"
                        +"<span class=\"iconfont\">&#xe629;"+o.popule+"</span>"
                        +"</p>"
                        +"<p class=\"countTime\">"
                        +"<span class=\"iconfont\">&#xe63f;</span>"
                        +"<span class=\"count\"></span>"
                        +"</p>"
                        +"<a class=\"nowbuy\" href=\"#\"><img src=\""+o.nowbuy+"\"/></a>"
                        +"</li>";

                    $("#manLike>ul").html(html0);
                })
                $("#manLike li").hover(function(){

                    $(this).children().last().children().animate({
                        right:0,
                        opacity:1,
                    },500);
                },function(){

                    $(this).children().last().children().animate({
                        right:-120,
                        opacity:1,
                    },500);
                });

            });


        }
    });
});







    //分类推荐
    //化妆水clearface   mask   base
var flag3 = true;
$(window).scroll(function(){
    $("#water").each(function(i,o){
        if($(window).height() + $(window).scrollTop() > $(o).offset().top
            && $(window).scrollTop() < $(o).height() + $(o).offset().top&&flag3){
            flag3 = false;
            $.get("../json/sort.json",function(data){
                // console.log(data)
                var html = "";
                $.each(data,function(i,o){
                    html += "<li>"
                        +"<a href=\"#\">"
                        +"<p class=\"pic\">"
                        +"<img src=\""+o.imgSrc+"\"/>"
                        +"</p>"
                        +"<p class=\"intro\">"
                        +""+o.intro+""
                        +"</p>"
                        +"<div class=\"btm\">"
                        +"<span class=\"price\">"
                        +"￥<strong>"+o.price+"</strong>"
                        +"</span>"
                        +" <span class=\"iconfont sales\">&#xe629;"+o.love+""
                        +"</span>"
                        +"</div>"
                        +"</a>"
                        +"</li>";
                    $("#water>ul").html(html);
                });
            });


        }
    });
});



//洗面

var flag4 = true;
$(window).scroll(function(){
    $("#water").each(function(i,o){
        if($(window).height() + $(window).scrollTop() > $(o).offset().top
            && $(window).scrollTop() < $(o).height() + $(o).offset().top&&flag4){
            flag4 = false;
            $.get("../json/clear.json",function(data){
                // console.log(data)
                var html = "";
                $.each(data,function(i,o){
                    html += "<li>"
                        +"<a href=\"#\">"
                        +"<p class=\"pic\">"
                        +"<img src=\""+o.imgSrc+"\"/>"
                        +"</p>"
                        +"<p class=\"intro\">"
                        +""+o.intro+""
                        +"</p>"
                        +"<div class=\"btm\">"
                        +"<span class=\"price\">"
                        +"￥<strong>"+o.price+"</strong>"
                        +"</span>"
                        +" <span class=\"iconfont sales\">&#xe629;"+o.love+""
                        +"</span>"
                        +"</div>"
                        +"</a>"
                        +"</li>";
                    $("#clearface>ul").html(html);
                });
            });
        }
    });
});




    //面膜
var flag5 = true;
$(window).scroll(function(){
    $("#water").each(function(i,o){
        if($(window).height() + $(window).scrollTop() > $(o).offset().top
            && $(window).scrollTop() < $(o).height() + $(o).offset().top&&flag5){
            flag5 = false;
            $.get("../json/mask.json",function(data){
                // console.log(data)
                var html = "";
                $.each(data,function(i,o){
                    html += "<li>"
                        +"<a href=\"#\">"
                        +"<p class=\"pic\">"
                        +"<img src=\""+o.imgSrc+"\"/>"
                        +"</p>"
                        +"<p class=\"intro\">"
                        +""+o.intro+""
                        +"</p>"
                        +"<div class=\"btm\">"
                        +"<span class=\"price\">"
                        +"￥<strong>"+o.price+"</strong>"
                        +"</span>"
                        +" <span class=\"iconfont sales\">&#xe629;"+o.love+""
                        +"</span>"
                        +"</div>"
                        +"</a>"
                        +"</li>";
                    $("#mask>ul").html(html);
                });
            });
        }
    });
});




    //底妆
var flag6 = true;
$(window).scroll(function(){
    $("#water").each(function(i,o){
        if($(window).height() + $(window).scrollTop() > $(o).offset().top
            && $(window).scrollTop() < $(o).height() + $(o).offset().top&&flag6){
            flag6 = false;
            $.get("../json/base.json",function(data){
                // console.log(data)
                var html = "";
                $.each(data,function(i,o){
                    html += "<li>"
                        +"<a href=\"#\">"
                        +"<p class=\"pic\">"
                        +"<img src=\""+o.imgSrc+"\"/>"
                        +"</p>"
                        +"<p class=\"intro\">"
                        +""+o.intro+""
                        +"</p>"
                        +"<div class=\"btm\">"
                        +"<span class=\"price\">"
                        +"￥<strong>"+o.price+"</strong>"
                        +"</span>"
                        +" <span class=\"iconfont sales\">&#xe629;"+o.love+""
                        +"</span>"
                        +"</div>"
                        +"</a>"
                        +"</li>";
                    $("#base>ul").html(html);
                });
            });
        }
    });
});




    //香氛
var flag7 = true;
$(window).scroll(function(){
    $("#water").each(function(i,o){
        if($(window).height() + $(window).scrollTop() > $(o).offset().top
            && $(window).scrollTop() < $(o).height() + $(o).offset().top&&flag7){
            flag7 = false;
            $.get("../json/fragrance.json",function(data){
                // console.log(data)
                var html = "";
                $.each(data,function(i,o){
                    html += "<li>"
                        +"<a href=\"#\">"
                        +"<p class=\"pic\">"
                        +"<img src=\""+o.imgSrc+"\"/>"
                        +"</p>"
                        +"<p class=\"intro\">"
                        +""+o.intro+""
                        +"</p>"
                        +"<div class=\"btm\">"
                        +"<span class=\"price\">"
                        +"￥<strong>"+o.price+"</strong>"
                        +"</span>"
                        +" <span class=\"iconfont sales\">&#xe629;"+o.love+""
                        +"</span>"
                        +"</div>"
                        +"</a>"
                        +"</li>";
                    $("#fragrance>ul").html(html);
                });
            });
        }
    });
});



var oNav = $('#LoutiNav');//导航壳
var aNav = oNav.find('li');//导航
var aDiv = $('.louceng');//楼层
//回到顶部
$(window).scroll(function(){
    var winH = $(window).height();//可视窗口高度
    var iTop = $(window).scrollTop();//鼠标滚动的距离

    if(iTop>=900){
        oNav.fadeIn(600);
        //鼠标滑动式改变
        aDiv.each(function(){
            if(winH+iTop - $(this).offset().top>winH/2){
                aNav.removeClass("active");
                aNav.eq($(this).index()).addClass("active");
            }
        })
    }else{
        oNav.fadeOut(600);

    }
})

//点击回到当前楼层
aNav.click(function(){
    var t = aDiv.eq($(this).index()).offset().top;
    $('body,html').animate({"scrollTop":t},500);
    $(this).addClass('active').siblings().removeClass('active');
});























